/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tds;

import java.util.*;

/**
 *
 * @author cwhitela
 */
public class MyDateFormatter {
	
	private HashMap<String, String> monthNumbers;
	
	public MyDateFormatter()
	{
		monthNumbers = new HashMap<String, String>();
		 ArrayList<String> months = new ArrayList<String>();
		 months.add("Jan");
		 months.add("Feb");
		 months.add("Mar");
		 months.add("Apr");
		 months.add("May");
		 months.add("Jun");
		 months.add("Jul");
		 months.add("Aug");
		 months.add("Sep");
		 months.add("Oct");
		 months.add("Nov");
		 months.add("Dec");
		 
		 Iterator<String> i = months.iterator();
		 int j = 1;
		 while (i.hasNext())
		 {
			 String jString = Integer.toString(j);
			 monthNumbers.put(i.next(), j < 10 ? "0".concat(jString) : jString);
			 ++j;
		 }
	}
	
	/*
	 * Split Date toString indices
	 * 0: day of week
	 * 1: month
	 * 2: day
	 * 3: time
	 * 4: offset
	 * 5: year
	 */
		
	public String getFormattedDateString(Date i)
	{
		return getFormattedDateString(i.toString());
	}
	
	public String getFormattedDateString(Tweet t)
	{
		return getFormattedDateString( t.dateTime );
	}
	
	public String getFormattedDateString(String s)
	{
		return getYearString(s) + "-" + getMonthNumString(s) + "-" + getDayNumString(s);
	}
	
	public String getFormattedDateTimeString(Date i)
	{
		return getFormattedDateTimeString(i.toString());
	}
	
	public String getFormattedDateTimeString(String s)
	{
		return getFormattedDateString(s) + " " + getFormattedTimeString(s);
	}
	
	private String getMonthNumString(String s)
	{
		return monthNumbers.get( s.split(" ")[1] );
	}
	
	private String getDayNumString(String s)
	{
		return s.split(" ")[2];
	}
	
	private String getYearString(String s)
	{
		return s.split(" ")[5];
	}
	
	public String getFormattedTimeString(String s)
	{
		return s.split(" ")[3];
	}
	
}
